

import java.util.HashSet;
import java.util.Objects;

public class hashset_exersice {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();

        hashSet.add(   new Employee("Sminth",10000,new MyDate(2002,11,23)) );
        //hashSet.add(   new Employee("Tom",20000,new Employee.MyDate(2000,11,23)) );
        hashSet.add(   new Employee("Sminth",10000,new MyDate(2002,11,23)) );
        System.out.println(hashSet);
    }
    //创建属性
    public  static  class Employee{
        private  String name;
        private double sal;
        private MyDate birthay;

        public Employee(String name, double sal, MyDate birthay) {
            this.name = name;
            this.sal = sal;
            this.birthay = birthay;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Employee employee = (Employee) o;
           // return birthay == employee.birthay && Objects.equals(name, employee.name);
            return Objects.equals(birthay, employee.birthay) && name==employee.name;
        }
        @Override
        public int hashCode() {
            return Objects.hash(name, birthay);
        }

        @Override
        public String toString() {
            return "Employee{" +
                    "name='" + name + '\'' +
                    ", sal=" + sal +
                    ", birthay=" + birthay +
                    '}';
        }


    }
}
 class MyDate{
    private  int year;
    private  int month;
    private  int date;

    public MyDate(int year, int month, int date) {
        this.year = year;
        this.month = month;
        this.date = date;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && month == myDate.month && date == myDate.date;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, date);
    }

     @Override
     public String toString() {
         return "MyDate{" +
                 "year=" + year +
                 ", month=" + month +
                 ", date=" + date +
                 '}';
     }
 }